<fieldset>
    <legend>Tham gia tổ chức đoàn thể</legend>
        <table class="responsive table">
            <thead>
                        <tr>
                            <th>STT</th>
                            <th>Tổ chức</th>
                            <th>Ngày tham gia</th>
                            <th>Chức vụ</th>
                            <th>Thao tác</th>
                        </tr>
                    </thead>
                    <tbody id="pub_organization_list">
                    </tbody>

        </table>
        <table>
            <tr>
                <th><?php echo $staff_pub_organization_form['pub_organization_id']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_pub_organization_form['pub_organization_id']->render(array("id" => "pub_organization_id", "class" => "text" ));  ?></td>
            </tr>
            <tr>
                <th><?php echo $staff_pub_organization_form['start_date']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><input id="staff_pub_organization_start_date" class="text datepicker"/></td>
            </tr>
            <tr>
                <th><?php echo $staff_pub_organization_form['position']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_pub_organization_form['position']->render(array("id" => "position", "class" => "text" ));  ?></td>
            </tr>
        </table>
        <button class="btn btn-info" type="button" href="#" onclick="add_pub_organization()">Thêm</button>
</fieldset>

<fieldset>
    <legend>Luân chuyển công tác</legend>
    <table class="responsive table">
            <thead>
                        <tr>
                            <th>STT</th>
                            <th>Đơn vị cũ</th>
                            <th>Vị trí công tác cũ</th>
                            <th>Đơn vị mới</th>
                            <th>Vị trí công tác mới</th>
                            <th>Ngày chuyển</th>
                            <th>Quyết định số</th>
                            <th>Thao tác</th>
                        </tr>
                    </thead>
                    <tbody id="transfer_list">
                    </tbody>

        </table>
        <table>
            <tr>
                <th><?php echo $staff_transfer_form['old_gov_organization_id']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_transfer_form['old_gov_organization_id']->render(array("id" => "old_gov_organization_id", "class" => "text" ));  ?></td>
                <th><?php echo $staff_transfer_form['old_job_title']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_transfer_form['old_job_title']->render(array("id" => "old_job_title", "class" => "text" ));  ?></td>
            </tr>
            <tr>
                <th><?php echo $staff_transfer_form['new_gov_organization_id']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_transfer_form['new_gov_organization_id']->render(array("id" => "new_gov_organization_id", "class" => "text" ));  ?></td>
                <th><?php echo $staff_transfer_form['new_job_title']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_transfer_form['new_job_title']->render(array("id" => "new_job_title", "class" => "text" ));  ?></td>
            </tr>
            <tr>
                <th><?php echo $staff_transfer_form['start_date']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><input id="staff_transfer_start_date" class="text datepicker"/></td>
            </tr>
            <tr>
                <th><?php echo $staff_transfer_form['document_id']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_transfer_form['document_id']->render(array("id" => "document_id", "class" => "text" ));  ?></td>
            </tr>
        </table>
        <button class="btn btn-info" type="button" href="#" onclick="add_staff_transfer()">Thêm</button>
</fieldset>

<fieldset>
    <legend>Khen thưởng kỷ luật</legend>
    <table class="responsive table">
            <thead>
                        <tr>
                            <th>STT</th>
                            <th>Tên</th>
                            <th>Mô tả</th>
                            <th>Ngày</th>
                            <th>Quyết định số</th>
                            <th>Thao tác</th>
                        </tr>
                    </thead>
                    <tbody id="event_list">
                    </tbody>

        </table>
        <table>
            <tr>
                <th><?php echo $staff_event_form['name']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_event_form['name']->render(array("id" => "staff_event_name", "class" => "text" ));  ?></td>
            </tr>
            <tr>
                <th><?php echo $staff_event_form['description']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_event_form['description']->render(array("id" => "staff_event_description", "class" => "text" ));  ?></td>
            </tr>
            <tr>
                <th><?php echo $staff_event_form['start_date']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><input id="staff_event_start_date" class="text datepicker"/></td>
            </tr>
            <tr>
                <th><?php echo $staff_event_form['document_id']->renderLabel(null, array("class"=>"form-label"));  ?></th>
                <td><?php echo $staff_event_form['document_id']->render(array("id" => "staff_event_document_id", "class" => "text" ));  ?></td>
            </tr>
        </table>
        <button class="btn btn-info" type="button" href="#" onclick="add_staff_event()">Thêm</button>
</fieldset>
<script>
    $(document).ready(function() {
        load_pub_organizations();
        load_staff_transfers();
        load_staff_events();
    });
    function load_pub_organizations() {
        html = '';
        <?php $count = 0 ?>
        <?php foreach ($pub_organizations as $pub_organization) : ?>
            <?php $count += 1 ?>
            html = html + '<tr><td>' + '<?php echo $count ?>' + '</td><td>' + '<?php echo $pub_organization->PubOrganization->name ?>' + '</td><td>'+
                '<?php echo $pub_organization->start_date ?>' + '</td><td>'+
                '<?php echo $pub_organization->position ?>' + '</td><td>'+
                '<div class="controls center">' +
                "<a href='#'" + "title='Remove task'"+ "class='tip'>"+ "<span onClick='remove_url(<?php echo $pub_organization->pub_organization_id ?>, <?php echo $staff->id ?>)' class='icon12 icomoon-icon-remove'>"+"</span>"+"</a>"+"</div>"+"</td>"+"</tr>";
        <?php endforeach ?>
        $('#pub_organization_list').html(html);
    }

    function load_staff_transfers() {
        html = '';
        <?php $count = 0 ?>
        <?php foreach ($staff->Transfers as $transfer) : ?>
            <?php $count += 1 ?>
            html = html + '<tr><td>' + '<?php echo $count ?>' + '</td><td>' +
                '<?php echo $transfer->OldGovOrganization->name ?>' + '</td><td>'+
                '<?php echo $transfer->old_job_title ?>' + '</td><td>'+
                '<?php echo $transfer->NewGovOrganization->name ?>' + '</td><td>'+
                '<?php echo $transfer->new_job_title ?>' + '</td><td>'+
                '<?php echo $transfer->start_date ?>' + '</td><td>'+
                '<?php echo $transfer->document_id ?>' + '</td><td>'+
                '<div class="controls center">' +
                "<a href='#'" + "title='Remove task'"+ "class='tip'>"+ "<span onClick='remove_url(<?php echo $transfer->id ?>)' class='icon12 icomoon-icon-remove'>"+"</span>"+"</a>"+"</div>"+"</td>"+"</tr>";
        <?php endforeach ?>
        $('#transfer_list').html(html);
    }

    function load_staff_events() {
        html = '';
        <?php $count = 0 ?>
        <?php foreach ($staff->Events as $event) : ?>
            <?php $count += 1 ?>
            html = html + '<tr><td>' + '<?php echo $count ?>' + '</td><td>' +
                '<?php echo $event->name ?>' + '</td><td>'+
                '<?php echo $event->description ?>' + '</td><td>'+
                '<?php echo $event->start_date ?>' + '</td><td>'+
                '<?php echo $event->document_id ?>' + '</td><td>'+
                '<div class="controls center">' +
                "<a href='#'" + "title='Remove task'"+ "class='tip'>"+ "<span onClick='remove_url(<?php echo $event->id ?>)' class='icon12 icomoon-icon-remove'>"+"</span>"+"</a>"+"</div>"+"</td>"+"</tr>";
        <?php endforeach ?>
        $('#event_list').html(html);
    }

    function add_pub_organization()
    {
        $.post("<?php echo url_for('@staff_add_pub_organization') ?>",
                {
                    staff_id: '<?php echo $staff->id ?>',
                    pub_id: $('#pub_organization_id').val(),
                    start_date: $('#staff_pub_organization_start_date').val(),
                    position: $('#position').val()
                }, function(data) {
                    if (data != 'error')
                        $('#pub_organization_list').html(data);
                    else
                        alert('Bạn đã tham gia tổ chức xã hội này.')
                }
        );
    }

    function add_staff_transfer()
    {
        $.post("<?php echo url_for('@staff_add_transfer') ?>",
                {
                    staff_id: '<?php echo $staff->id ?>',
                    old_gov_organization_id: $('#old_gov_organization_id').val(),
                    new_gov_organization_id: $('#new_gov_organization_id').val(),
                    start_date: $('#staff_transfer_start_date').val(),
                    document_id: $('#document_id').val(),
                    new_job_title: $('#new_job_title').val(),
                    old_job_title: $('#old_job_title').val(),
                }, function(data) {
                    if (data != 'error')
                        $('#transfer_list').html(data);
                    else
                        alert('Bạn đã tham gia tổ chức xã hội này.')
                }
        );
    }

    function add_staff_event()
    {
        $.post("<?php echo url_for('@staff_add_event') ?>",
                {
                    staff_id: '<?php echo $staff->id ?>',
                    name: $('#staff_event_name').val(),
                    description: $('#staff_event_description').val(),
                    start_date: $('#staff_event_start_date').val(),
                    document_id: $('#staff_event_document_id').val()
                }, function(data) {
                    if (data != 'error')
                        $('#event_list').html(data);
                    else
                        alert('Bạn đã tham gia tổ chức xã hội này.')
                }
        );
    }
</script>
